<?php
namespace app\admin\model;

use think\Model;

/**
 * 官网图片模型表
 * @package app\admin\model
 */
class GwTemplate extends Model
{
    public static function getList($request)
    {
        $data = self::field('id,name,content')->paginate($request['limit'], false, ['query' => $request])
            ->each(function ($item, $key) {
                $item->details = '<a href="javascript:;" style="color:#01aaed;" onClick="open_window(\'查看详情\',\'' . $item->id . '\')"><u>查看详情</u></a>';
                // switch ($item->template_type) {
                //     case '1':
                //         $item->details = '<a href="javascript:;" style="color:#01aaed;" onClick="open_window(\'点击查看图片\',\'' . $item->id . '\')"><u>点击查看图片</u></a>';
                //         // $item->details = '<a href="/admin/gw_template/show?id=' . $item->id . '" target="_blank" style="color:#01aaed;">点击查看图片</a>';
                //         break;
                //     case '2':
                //         // $item->details = '<a href="/admin/gw_template/show?id=' . $item->id . '" target="_blank" style="color:#01aaed;">查看内容</a>';
                //         $item->details = '<a href="javascript:;" style="color:#01aaed;" onClick="open_window(\'查看内容\',\'' . $item->id . '\')"><u>查看内容</u></a>';
                //         break;
                //     default:
                //         $item->details = '';
                //         break;
                // }

            });
        return $data->toArray();
    }

    public static function add($data)
    {
        try {
            self::create($data);
            return ['code' => '200', 'msg' => '提交成功'];
        } catch (\Exception $e) {

            return ['code' => '422', 'msg' => '提交失败'];
        }
    }

    public static function upd($data)
    {
        try {
            self::where('id', $data['id'])->update($data);
            return ['code' => '200', 'msg' => '更新成功'];
        } catch (\Exception $e) {

            return ['code' => '422', 'msg' => '更新失败'];
        }
    }
}
